package GMDPRE

import (
	"fmt"
)

func testSm3Hash() {
	var s string
	var hash []uint8

	s = "abc"
	hash = []uint8{
		0x66, 0xC7, 0xF0, 0xF4, 0x62, 0xEE, 0xED, 0xD9, 0xD1, 0xF2, 0xD4, 0x6B, 0xDC, 0x10, 0xE4, 0xE2,
		0x41, 0x67, 0xC4, 0x87, 0x5C, 0xF2, 0xF7, 0xA2, 0x29, 0x7D, 0xA0, 0x2B, 0x8F, 0x4B, 0xA8, 0xE0}
	fmt.Printf("Test Sm3Hash is correct: %d\n", BytesEqual(hash, Sm3Hash(StringToBytes(s), uint64(len(s))), Sm3HashSize))
}

func testSm3HashV2() {
	var s string
	var hash []uint8

	s = "66C7F0F462EEEDD9D1F2D46BDC10E4E24167C4875CF2F7A2297DA02B8F4BA8E0"
	hash = []uint8{
		0xAD, 0xA6, 0xED, 0x14, 0xE6, 0x61, 0xD1, 0xC7, 0x21, 0x73, 0xB2, 0x58, 0x9F, 0x03, 0xFD, 0x3A,
		0xEC, 0x3A, 0x5D, 0xF0, 0xDE, 0xCA, 0xBB, 0x7E, 0x4C, 0x42, 0x0C, 0x61, 0x3C, 0x79, 0xD5, 0x2F}
	fmt.Printf("Test Sm3Hash V2 is correct: %d\n", BytesEqual(hash, Sm3Hash(StringToBytes(s), uint64(len(s))), Sm3HashSize))
}

func testSm3HashV3() {
	var s string
	var hash string

	s = "1111111111111111111111111111111111111111111111111111122222222222222222222222222222222222222222222222222222222222222233333333333333333333333333333333333333333333344444444444444444444444444444444"
	hash = "C8171D3225D29E9F7E50F4E2F7BDB41F8871FD9DCE4AE72C7E28983D32B5F594"
	fmt.Printf("Test Sm3Hash V3 is correct: %d\n", BytesEqual(HexToBytes(hash), Sm3Hash(StringToBytes(s), uint64(len(s))), Sm3HashSize))
}

func testSm3HashV4() {
	var hash string

	s1 := "1111111111111111111111111111111111111111111111111111122"
	s2 := "2222222222222222222222222222222222222222222222222222222222222333333333"
	s3 := "33333333333333333333333333333333333344444444444444444444444444444444"
	hash = "C8171D3225D29E9F7E50F4E2F7BDB41F8871FD9DCE4AE72C7E28983D32B5F594"

	var ctx Sm3Ctx
	Sm3Init(&ctx)
	Sm3Update(&ctx, StringToBytes(s1), uint64(len(s1)))
	Sm3Update(&ctx, StringToBytes(s2), uint64(len(s2)))
	Sm3Update(&ctx, StringToBytes(s3), uint64(len(s3)))

	fmt.Printf("Test Sm3Hash V4 is correct: %d\n", BytesEqual(HexToBytes(hash), Sm3Finish(&ctx), Sm3HashSize))
}

func TestSm3() {
	fmt.Println("+------------------------------------------------------------------------------+")
	fmt.Println("+---    Test module  --->  sm3")
	testSm3Hash()
	testSm3HashV2()
	testSm3HashV3()
	testSm3HashV4()
	fmt.Println("+------------------------------------------------------------------------------+")
}
